<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改课程</title>
    <script src="js/base.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }
        h1 {
            font-size: 2em;
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }
        input[type="text"] {
            width: 30%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 14px;
        }
        button {
            padding: 10px 20px;
            margin: 10px 0;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .form-container {
            width: 100%;
            max-width: 400px;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center; /* 添加居中对齐 */
        }
        .button-container {
            display: flex;
            justify-content: center; /* 按钮居中 */
        }
        span {
            font-weight: bold;
            color: #555;
        }
    </style>
</head>
<body>
<h1>修改课程</h1>
课程号：<span id="courseId"></span><br/>
课程名称：<input type="text" id="name"><br/>
授课教师：<input type="text" id="tname"><br/>
教室容量：<span id="maxLimit"></span><br/>
<div class="button-container">
    <button onclick="onEditClick()">确认修改</button></div>
<script>
    let id=localStorage.getItem("editCourse_id");
    let name= localStorage.getItem("editCourse_name");
    let tname=localStorage.getItem("editCourse_tname");
    let maxLimit=localStorage.getItem("editCourse_maxLimit");
    document.getElementById("courseId").innerHTML=id;
    document.getElementById("name").value=name;
    document.getElementById("tname").value=tname;
    document.getElementById("maxLimit").innerHTML=maxLimit;



    function onEditClick(){
        let url="http://localhost:8080/teacher/editCourse";
        let method="post";
        let json={};
        json.id=document.getElementById("courseId").innerHTML;
        json.name=document.getElementById("name").value;
        json.tname=document.getElementById("tname").value;
        json.maxLimit=document.getElementById("maxLimit").innerHTML;
        $.rest(url,method,json,function (r){
            if (r.code==200){
                alert("修改成功");
                window.location.href="teacherIndex.html";
            }else if(r.code==500){
                alert("教师不存在");
            }else{
                alert("修改错误");
            }
        });

    }
</script>
</body>
</html>